import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
//解决导航冗余
const orginalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return orginalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'index',
    component: () => import('../views/index.vue'),
    redirect: "/newSong",
    children: [{
      path: "/newSong",
      component: () => import("../components/newSong.vue")
    }, {
      path: "/region",
      component: () => import("../components/region.vue")
    }
    ]
  },
  {
    path: "/singer",
    name: "singer",
    component: () => import("../views/singer.vue")
  },
  {
    path: "/rank",
    name: "rank",
    component: () => import("../views/rank.vue"),
    redirect: "/list",
    children: [{
      path: "/list",
      component: () => import("../components/list.vue")
    }]
  },
  {
    path: "/classify",
    name: "classify",
    component: () => import("../views/classify.vue"),
    redirect: "/songClassify",
    children: [{
      path: "/songClassify",
      component: () => import("../components/songClassify.vue")
    }]
  },
  {
    path: "/song",
    name: "song",
    component: () => import("../views/song.vue")
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/login.vue")
  },
  {
    path: "/register",
    name: "register",
    component: () => import("../views/register.vue")
  },
  {
    path: "/person",
    name: "person",
    component: () => import("../views/person.vue"),
    redirect: "/like",
    children: [
      {
        path: "/like",
        component: () => import("../components/like.vue")
      },
      {
        path: "/information",
        component: () => import("../components/information.vue")
      }
    ]
  },
  {
    path: "/search/:w",
    name: "search",
    component: () => import("../views/search.vue")
  },
  {
    path: "/playLists",
    name: "playLists",
    component: () => import("../views/playLists.vue")
  },
  {
    path: "/music",
    name: "music",
    component: () => import("../views/music.vue")
  },
  {
    path: "/admin",
    name: "admin",
    component: () => import("../views/admin.vue"),
    redirect: "/all",
    children: [
      {
        path: "/all",
        component: () => import("../components/userAll.vue")
      },
      {
        path: "/listAll",
        component: () => import("../components/listAll.vue")
      },
      {
        path: "/songAll",
        component: () => import("../components/songAll.vue")
      }
    ]
  },
  {
    path: "/singerDetails",
    name: "singerDetails",
    component: () => import("../views/singerDetails.vue"),
  },
  {
    path: "/information2",
    name: "information2",
    component: () => import("../components/information2.vue"),
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
